/**
 * 
 */
package com.gxa.ehome.service.impl;


import com.gxa.ehome.dao.CpDao;
import com.gxa.ehome.dao.impl.CpDaoImpl;
import com.gxa.ehome.entity.Cp;
import com.gxa.ehome.service.CpService;

import java.util.List;

/**
 * @author bilei
 * @date 2021年3月31日
 */
public class CpServiceImpl implements CpService {

	// UserDao对象解决具体的持久化操作

	CpDao cpDao= new CpDaoImpl();


	@Override
	public List<Cp> selectAllCp() throws Exception {
		List<Cp> cpList=cpDao.selectAll();

		return cpList;
	}
	@Override
	public List<Cp> selectAllByPage(Integer page, Integer size) throws Exception {
		List<Cp> userList = cpDao.selectByPage(page, size);
		return userList;
	}

	@Override
	public Integer insert(Cp cp) throws Exception {

			Integer lines = cpDao.insert(cp);
			return  lines;

	}

	@Override
	public Integer update1(Integer id, Cp cp) throws Exception {
		Cp selectedUser = cpDao.selectById(id);
		if(selectedUser != null){
			selectedUser.setName(cp.getName());
			selectedUser.setDesc(cp.getDesc());
			selectedUser.setImg(cp.getImg());
			selectedUser.setRole(cp.getRole());
			selectedUser.setColletExpire(cp.getColletExpire());
			selectedUser.setUseExpire(cp.getUseExpire());
			selectedUser.setInUse(cp.isInUse());
		}
		Integer update = cpDao.update1(id, selectedUser);
		return update;
	}
}
